export default class SoundManager{
    public static bgMiuses:Array<string>=["bg1.mp3"];
	public static soundPath:string="sound/"

    private static bgSoundChannel:Laya.SoundChannel;
    private static mMusicMute:boolean=false;
    private static mSoundMute:boolean=false;
    private static mCurrMusic:string;
    private static preSound:string;
    private static preSoundTime:number=0;
    public static playBgMiuse(_index:number=0) {
       let turl = this.bgMiuses[_index];
        if(this.mMusicMute)this.playMiuse(turl);
    }
    
    public static playMiuse(url){
        if(!this.mMusicMute){
            this.mCurrMusic = url;
            this.stopMiuse();
             let file=this.soundPath+url;
             this.bgSoundChannel = Laya.SoundManager.playMusic(file,0);
        }
    }
    public static stopMiuse = function(){
        if(this.bgSoundChannel){
            //this.bgSoundChannel
            this.bgSoundChannel.stop();
        }
    }
	
	public static resumeMusic(){
        if(!this.mMusicMute){
            if(this.bgSoundChannel){
                //this.bgSoundChannel
                this.bgSoundChannel.resume();
            }

        }
	}
    public static playSound(url){
        let time = new Date().getTime();
        if(this.preSound==url){
            if(time-this.preSoundTime<500)return;
        }
        this.preSound=url;
        if(!this.mSoundMute){
            this.preSoundTime=time;
            let file=this.soundPath+url;
            Laya.SoundManager.playSound(file,1);     
        }
    }

    public static get soundMute(){
        return this.mSoundMute;
    }

    public static set soundMute(_value:boolean){
        this.mSoundMute=_value;
    } 

    public static get musicMute(){
        return this.mMusicMute;
    }

    public static set musicMute(_value:boolean){
        this.mMusicMute=_value;
        if(_value){
            this.stopMiuse();
        }else{
            if(this.mCurrMusic)this.playMiuse(this.mCurrMusic);
        }
    } 
}